#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


Loop, {

StartTime := A_TickCount

Random, red_rand, 0, 255
Random, green_rand, 0, 255
Random, blue_rand, 0, 255
current_distance := 442 ; Diagonal distance between 0,0,0 and 255,255,255
current_name := ""

Loop, Read, % "HTML X11 Color List.csv"
{
StringSplit, linepiece, A_LoopReadLine, `,
distance := Sqrt( ( red_rand - linepiece1 )**2 + ( green_rand - linepiece2 )**2 + ( blue_rand - linepiece3 )**2 )
If (distance < current_distance)
	{
	current_distance := distance
	current_name := linepiece4
	}

}

ElapsedTime := A_TickCount - StartTime
MsgBox,1, Find Qualitative Color Name, Using %current_name% for`n%red_rand% %green_rand% %blue_rand%`n(%ElapsedTime% ms)
IfMsgBox, Cancel
	ExitApp
}